<!DOCTYPE HTML>
<html>
<head>
    <title>添加商品父分类</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/stylesheets/formdata.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body>
  <div class="container">
    <form id="form1" name="form1" method="post" action='/getdata/goodsTypeIconUpload' enctype="multipart/form-data" >
        <input name="id" class="mini-hidden" />
        <div style="padding-left:11px;padding-bottom:5px; margin-top: 50px">
            <table style="table-layout:fixed; margin: 0 auto;text-align: center;">
                <tr>
                    <td style="width:60px;">分类名称：</td>
                    <td >
                        <input name="name" class="mini-textbox" style="width:155px;" required="true"/>
                    </td>
                    <td style="width:60px;">分类图标：</td>
                    <td >
                        <input id="image" name="image" type="file" style="width:155px;" required="true"/>
                    </td>
                </tr>
            </table>
        </div>
        <div style="text-align:center;padding:10px;">
            <!--<input type='submit' style="width:60px;margin-right:20px;" value='提交'/>-->
            <a class="mini-button" iconCls="icon-ok" onclick="onOk">确定</a>
            <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
        </div>
    </form>
  </div>
</body>
<script>
  mini.parse();

  function onOk(e) {
    var form = new mini.Form("#form1");
    form.validate()
    if (form.isValid() == false){
      var name = mini.get('name').value;
      if (name.length < 1){
        alert('请输入分类名称!');
        return;
      }
    } else {
      var image = document.getElementById("image").value;
      if (image.length < 1){
        alert('请选择分类图标!');
        return;
      }
      document.form1.submit().then(result=>{
        if (result){
          CloseWindow("OK");
        }
      }).catch(error=>{
        console.log(error)
      });
    }
  }

  function onCancel(e) {
    CloseWindow("cancel");
  }
  //    关闭窗口
  function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
      if (confirm("数据被修改了，是否先保存？")) {
        return false;
      }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
  }

</script>
</html>